<?

class CsvUtils{
	
	public static function parse_csv($file, $options = null) {
	    $delimiter = empty($options['delimiter']) ? ";" : $options['delimiter'];
	    $to_object = empty($options['to_object']) ? false : true;
	    $str = iconv('WINDOWS-1250', 'UTF-8', file_get_contents($file));
	    $lines = explode("\n", $str);
	    $headers = array('a;b;c;d;e;f;g');
	    $lines = array_merge($headers, $lines);
	    
	    $field_names = explode($delimiter, array_shift($lines));
	    foreach ($lines as $line) {
	        // Skip the empty line
	        if (empty($line)) continue;
	        $fields = explode($delimiter, $line);
	        $_res = $to_object ? new stdClass : array();
	        foreach ($field_names as $key => $f) {
	            if ($to_object) {
	                $_res->{$f} = $fields[$key];
	            } else {
	                $_res[$f] = $fields[$key];
	            }
	        }
	        $res[] = $_res;
	    }
	    return $res;
	}
}

?>